<?php

/**
 * This is the model class for table "personal".
 *
 * The followings are the available columns in table 'personal':
 * @property integer $ID
 * @property integer $PERSONAL_CDOE
 * @property integer $IDCARD
 * @property string $PERSONAL_NAME
 * @property string $PERSONAL_LASTNAME
 * @property string $ADDRESS
 * @property string $TEL
 * @property string $FAX
 * @property string $EMAIL
 * @property integer $depart_id
 * @property integer $postion_id
 * @property string $PERSONAL_IMAGES
 */
class Personal extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Personal the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'personal';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('PERSONAL_CDOE, IDCARD, PERSONAL_NAME, PERSONAL_LASTNAME, ADDRESS, TEL, FAX, EMAIL, depart_id, postion_id, PERSONAL_IMAGES', 'required'),
			array('PERSONAL_CDOE, IDCARD, depart_id, postion_id', 'numerical', 'integerOnly'=>true),
			array('PERSONAL_NAME, PERSONAL_LASTNAME, ADDRESS, TEL, FAX, EMAIL, PERSONAL_IMAGES', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID, PERSONAL_CDOE, IDCARD, PERSONAL_NAME, PERSONAL_LASTNAME, ADDRESS, TEL, FAX, EMAIL, depart_id, postion_id, PERSONAL_IMAGES', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'PERSONAL_CDOE' => 'Personal Cdoe',
			'IDCARD' => 'Idcard',
			'PERSONAL_NAME' => 'Personal Name',
			'PERSONAL_LASTNAME' => 'Personal Lastname',
			'ADDRESS' => 'Address',
			'TEL' => 'Tel',
			'FAX' => 'Fax',
			'EMAIL' => 'Email',
			'depart_id' => 'Depart',
			'postion_id' => 'Postion',
			'PERSONAL_IMAGES' => 'Personal Images',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		
        $search = $_POST['keywords'];
        $criteria = new CDbCriteria; // เรียกค้นหาแบบ Criteria
        // $criteria->condition = "PUBLISHED <> 'N'";
        if (isset($search)) {
            // $criteria->with = array('TCustomer');
            $criteria->condition = "
PERSONAL_CDOE LIKE('%$search%')	OR      
IDCARD LIKE('%$search%')	OR      
PERSONAL_NAME LIKE('%$search%')	
    
";
          
        }
        $criteria->order = 't.PERSONAL_NAME ASC'; // เรียงข้อมูลแบบ DESC
        // ทำการ return ค่า แบบ CActiveDataProvider
        return new CActiveDataProvider($this, array(
            'criteria' => $criteria, // ใส่เงื่อนไขในการแสดงผล
            'pagination' => array('pageSize' => 15), // จำนวนที่แสดงต่อหน้า
        ));
	}
}